{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2 有监督学习\n",
    "from sklearn.linear_model import LinearRegression #导入线性回归模型\n",
    "\n",
    "X = [[10.0], [8.0], [13.0], [9.0], [11.0], [14.0], [6.0], [4.0], [12.0], [7.0], [5.0]]  # 输入特征\n",
    "\n",
    "y = [8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68] # 目标变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.0000909090909094\n",
      "[0.50009091]\n",
      "[ 8.001       7.00081818  9.50127273  7.50090909  8.50109091 10.00136364\n",
      "  6.00063636  5.00045455  9.00118182  6.50072727  5.50054545]\n"
     ]
    }
   ],
   "source": [
    "model = LinearRegression() # 实例化模型\n",
    "\n",
    "model.fit(X, y) # 模型训练\n",
    "\n",
    "print(model.intercept_) # 模型截距\n",
    "print(model.coef_) # 模型系数\n",
    "\n",
    "y_pred = model.predict(X) # 模型预测\n",
    "\n",
    "print(y_pred) # 模型预测值"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ml",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
